package com.itheima.service.impl;

import com.itheima.dao.BookDao;
import com.itheima.domain.Book;
import com.itheima.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    //自动装配: 从IOC容器(父容器)中获取bean
    @Autowired
    private BookDao bookDao;

    //返回值: 执行成功与否的结果, true表示成功,待会扩展
    public boolean save(Book book) {
        int count = bookDao.save(book);
//        if(count == 0){
//            //添加的时候影响的行数是0,说明添加失败了
//            return false;
//        }else{
//            return true;
//        }
        return count != 0;
    }

    public boolean update(Book book) {
        int count = bookDao.update(book);
        return count != 0;
    }

    public boolean delete(Integer id) {
        int count = bookDao.delete(id);
        return count != 0;
    }

    public Book getById(Integer id) {
        return bookDao.getById(id);
    }

    public List<Book> getAll() {
        return bookDao.getAll();
    }
}
